<?php
/**
 * 卡密批次
 * @link https://www.leadshop.vip/
 * @copyright Copyright ©2020-2021 浙江禾成云计算有限公司
 */

namespace card\models;

use framework\common\CommonModels;

class CardBatch extends CommonModels
{

    /**
     * 实现数据验证
     * 需要数据写入，必须在rules添加对应规则
     * 在控制中执行[模型]->attributes = $postData;
     * 否则会导致验证不生效，并且写入数据为空
     * @return [type] [description]
     */
    public function rules()
    {
        return [
            //基本信息设置
            [['num', 'start_index', 'expire_day', 'amount', 'length'], 'required'],
            [['expire_day', 'length'], 'integer', 'min' => 1],
            [['start_index'], 'integer', 'min' => 0],
            ['perfix', 'string', 'max' => 40],
            [['length'], 'integer', 'min' => 1, 'max' => 40],
            [['num'], 'integer', 'min' => 1, 'max' => 999999],
            [['amount'], 'number', 'min' => 0.01],
            [['page_id'], 'integer', 'min' => 0],
            [['name'], 'string'],
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios['create'] = ['num', 'perfix', 'length', 'start_index', 'expire_day', 'amount', 'page_id', 'name'];
        $scenarios['delete'] = ['is_deleted', 'deleted_time'];
        return $scenarios;
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'page_id' => '绑定微页面id',
            'name' => '批次名称',
            'num' => '数量',
            'perfix' => '卡号前缀',
            'length' => '卡号长度',
            'start_index' => '起始值',
            'expire_day' => '有效时间',
            'amount' => '金额',
            'AppID' => 'App ID',
            'created_time' => 'Created Time',
            'updated_time' => 'Updated Time',
            'deleted_time' => 'Deleted Time',
            'is_deleted' => 'Is Deleted',
        ];
    }
}